home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10149 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: rznews.rrze.uni-erlangen.de!news
  2. From: elmar.vogt@rzmail.uni-erlangen.de (Elmar Vogt)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: A question of (lexical) style
  5. Date: 6 Mar 1996 12:29:41 GMT
  6. Organization: LUR, University of Erlangen.
  7. Message-ID: <4hk0fl$irl@rznews.rrze.uni-erlangen.de>
  8. References: <313c99bc.0@193.89.47.9>
  9. NNTP-Posting-Host: faust207.lstm.uni-erlangen.de
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In article <313c99bc.0@193.89.47.9>, elgaard@dk-online.dk says...
  15. >
  16. >A question of (lexical) style
  17. >
  18. >I am currently writing guidelines for C++ programmers, and I am in doubt 
  19. about h
  20. >ow to place * and & in declarations.
  21. >
  22.  
  23. I fully agree that there is no universal 'right' or 'wrong' style, just 
  24. taste.
  25.  
  26. My personal convention is, founded on the (rough) equivalence of asterisks 
  27. and brackets:
  28. If variable _bar_ of type _foo_ is to be considered an array, I will write
  29.     foo    *bar;
  30.  
  31. If _bar_ is a pointer to a _foo_ instance, it's
  32.     foo*    bar;
  33.  
  34. This notation appears to be more logical to me, since -logically, not 
  35. grammatically- in the first case, if I want to use a _bar_ element, I 
  36. usually write
  37.     bar[i]=...;
  38. thus exchanging '*' and '[]' in a loose manner, and considering both a 
  39. part of _bar_'s _name_, instead of _type_.
  40. Obviously, if bar is just a pointer, I can't simply write bar[i]. Would 
  41. its name be written _*bar_, I would more easily be mislead to believe I 
  42. could write bar[i].
  43.  
  44. It's just I once consider the asterisk a part of the name, when it's 
  45. really an array, and once a part of the type, when it's a pointer.
  46.  
  47. Does this sound plausible?
  48.  
  49. Elmar
  50.  
  51. -- 
  52. --
  53. /----------------------------------------------------------------\
  54. | Elmar Vogt : MS->PhD | voice: (+49)9131/761-207; fax: ...-202  |
  55. | LUR, Schottkystr. 10 |http://www.rrze.uni-erlangen.de/~iwur08/ |
  56. |University of Erlangen|    Elmar.Vogt@rzmail.uni-erlangen.de    |
  57. |91058 Erlangen-Germany|    Vogt@nt.e-technik.uni-erlangen.de    |
  58. |-------- VIS VISCERIS, NON FERRO FERTUR (T. Doom) --------------|
  59. |SCA: Agilmar von Sevelingen; Fencing, Calligraphy, Jewelry, Food|
  60. \----------------------------------------------------------------/
  61.  
  62.